home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / doc / recomp < prev    next >
Encoding:
Text File  |  1997-08-18  |  6.1 KB  |  175 lines  |  [TEXT/R*ch]

  1. How to compile the Moscow ML compiler for DOS (assuming the runtime
  2. system is unmodified):
  3.  
  4. You will need: 
  5.     * the Moscow ML sources
  6.     * the djgpp compiler
  7.     * the perl utility
  8.     * a working runtime system (camlrun) version 0.7m1 for Moscow ML
  9.  
  10.  
  11. Initial compilation:
  12.  
  13. (1) To initially compile the entire system (except the runtime
  14.     system), execute
  15.     make world 
  16.     in directory mosml/src.  
  17.  
  18. (2) If you DO NOT have the binaries, then execute
  19.     make install
  20.     in directory mosml/src.  This installs mosmltop, mosmlcmp, and mosmllnk
  21.     in directory mosml/lib, and the small C executables mosml and mosmlc
  22.     in directory mosml/bin.  These executables invoke the runtime system 
  23.     (camlrun) to read and execute the bytecode files mosmltop etc.
  24.  
  25. Recompilation:
  26.  
  27. (1) To recompile just the compiler (the top-level system mosmltop, the
  28.     batch compiler mosmlcmp, and the batch linker mosmllnk), execute
  29.     make clean all
  30.     in mosml/src/compiler.
  31.  
  32. (2) [Do this only if you are quite certain that the new version works]
  33.     To make the newly compiled version the current one, execute
  34.     make install
  35.     in mosml/src/compiler.  This copies the fresh mosmltop, mosmllnk, and
  36.     mosmlcmp to mosml/lib.  It leaves the bytecode files in mosml/src
  37.     unchanged.  This intentional.
  38.  
  39.  
  40. There are two binding times in the making of the batch compiler:
  41.  
  42.     compilation mosmlc -c (bytecode)
  43.     linking     mosmlc -o (C primitives and libraries)
  44.  
  45.     When compiling user source code, the compiler reads and uses
  46.     the current libraries, not those that existed when the
  47.     compiler itself was built.
  48.  
  49. There are three binding times in the making of the interactive system:
  50.  
  51.     compilation    mosmlc -c (bytecode)
  52.     linking        mosmlc -o (C primitives, libraries used inside mosml)
  53.  
  54.     When compiling code entered at top-level, or compiling via 
  55.     function compile, the interactive system reads and uses the
  56.     current libraries, not those that existed when the top-level
  57.     system itself was built.
  58.  
  59. Bytecode instructions: The set of bytecode instructions is defined in
  60. runtime/interp.c and runtime/instruct.h, which must agree.  File
  61. compiler/Opcodes.sml is derived automatically from runtime/instruct.h.
  62. The bytecode generated by the compiler (mosmlcmp and mosmltop) depends
  63. on Opcodes.sml.  The bytecode can run only on the runtime system for
  64. which it is generated.
  65.  
  66. C primitives: The set of C primitives is defined by the collection of
  67. runtime/ files listed in variable PRIMS in runtime/Makefile; the C
  68. primitives are the functions annotated with /* ML */ in those files.
  69. File runtime/primitives is derived automatically from PRIMS and those
  70. files.  File compiler/Prim_c.sml is derived automatically from
  71. runtime/primitives.  The linking performed by the linker mosmllnk and
  72. the load function in mosmltop depends on Prim_c.sml.  A file linked
  73. for a given runtime system can run only on that system.
  74.  
  75. Libraries: The batch compiler (mosmlcmp and mosmllnk) and the lexer
  76. generator (mosmllex) are fully linked and independent of the libraries
  77. at runtime.
  78.  
  79. The interactive system (mosmltop) depends on the libraries present at
  80. runtime, not for its internal operation, but for the initial
  81. environment seen by the user.  File compiler/Config.mlp determines
  82. which libraries are loaded and which are open in the initial
  83. environment in the interactive system.
  84.  
  85.  
  86.  
  87. Bytecode, exceptions and global arguments:
  88.  
  89. In src/runtime, files interp.c and instruct.h must agree on the
  90. defined bytecode instructions; compiler/Opcodes.sml is derived from the
  91. latter.  
  92.  
  93.  
  94. The compiler back-end's internal representation of bytecode
  95. instructions is defined in src/compiler/Prim.sml.  When adding a new
  96. instruction, file src/compiler/Emitcode.sml must be updated to emit
  97. code if the new primitive takes an argument; whereas file
  98. src/compiler/Prim_opc.sml must be updated if the new primitive is
  99. argumentless.  File src/compiler/Pr_lam.sml must be updated to print
  100. the new primitive.  Finally, file src/compiler/Primdec.sml, which maps
  101. string names to the internal representation, may be updated if the new
  102. primitive needs to be externally visible (that is, usable in prim_val
  103. declarations).
  104.  
  105. The compiler front-end's internal representation of SML primitives is
  106. defined in src/compiler/Smlprim.sml; for binary primitives there are
  107. usually two versions: MLPxxx and MLPxxx_c, where the latter is for a
  108. fully applied version, which can be evaluated more efficiently.  The
  109. mapping to the bytecode primitives is done in file
  110. src/compiler/Front.sml, which also takes care of the optimization for
  111. fully applied primitives.  The front-end primitives are usually used
  112. when defining SML pervasives in src/compiler/Smlperv.sml.
  113.  
  114. Files src/compiler/Smlexc.sml and src/runtime/fail.h must agree on the
  115. exceptions they define, since the latter is used to generate
  116. src/compiler/Predef.sml, which is read by Symtable.sml and hence used
  117. in the compiler.
  118.  
  119.  
  120. Bootstrapping, after extending the set of C primitives
  121. ------------------------------------------------------
  122.  
  123. (1) Compile everything 
  124.     and make a backup of camlrunm, mosmllnk, mosmlcmp, mosmllex
  125. (2) Extend the set of primitives
  126. (3) Recompile runtime
  127. (4) Relink mosmllnk 
  128. (5) Promote mosmllnk to src/
  129. (6) Relink mosmllnk, mosmlcmp, mosmllex
  130. (7) Promote mosmllnk, mosmlcmp, mosmllex to src/
  131. (8) Promote camlrunm to src/
  132. (9) Recompile everything again
  133.  
  134.  
  135. Cross-compiling from Linux to DOS
  136. ---------------------------------
  137.  
  138. 0. In mosml/src, 
  139.     make clean world
  140.  
  141. 1. In mosml/src/runtime, edit Makefile to have
  142.     PRIMS=$(DOSPRIMS)
  143.  
  144. 2. Do
  145.     rm primitives prims.c
  146.     make prims.c
  147.  
  148. 3. In mosml/src/compiler, 
  149.     make mosmllnk
  150.     mv mosmllnk ../mosmllnk.dos
  151.  
  152. 4. Edit mosml/src/Makefile.inc to have
  153.     CPP=/lib/cpp -P -traditional -Uunix -Dmsdos
  154.  
  155. 5. In mosml/src/mosmllib
  156.     make clean all
  157.  
  158. 6. In mosml/src/compiler
  159.     make clean dos
  160.  
  161. 7. Move files mosmllnk and mosmlcmp to DOS (/cdisk/mosml/src).
  162.    These are now compatible with the DOS version of the runtime.
  163.  
  164. 8. To bootstrap the DOS version, copy all sources to DOS, 
  165.    copy compile/Lexer.{sig.sml} to DOS, 
  166.    and do 
  167.     make
  168.    in mosmllib and compiler.
  169.    Recompile mosmllex and toolssrc.
  170.    Then promote the generated mosmllnk and mosmlcmp, 
  171.    and do 
  172.     make clean world
  173.    in mosml/src.
  174.  
  175.